import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class sql {

    static final String DRIVER_CLASS = "org.h2.Driver";//driver,warning:case sensitive 
    static final String JDBC_URL = "jdbc:h2:tcp://localhost/~/test";
    static final String USER = "sa";//username
    static final String PASSWORD = "123"; //password
    
    
      public static String show(String a) throws Exception {
        Class.forName(DRIVER_CLASS);//load driver
        Connection conn = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
        Statement stmt = conn.createStatement();// createһ��Statement�  
        ResultSet rs = stmt.executeQuery("select * from stu where name=" + "'" + a + "'");
        // ResultSet rs = stmt.executeQuery("select * from stu_info where name='" + a + "'");
        String ss;
//        while(rs.next()){            
//         ss=rs.getString("sex");
//        }

        //p(rs.getString("student_id") + "\t" + rs.getString("name") + "\t" + rs.getString("sex") + "\t" + rs.getString("Esocre") + "\t" + rs.getString("Msocre") + "\t" + rs.getString("Csocre"));
        if (rs.next()) {
            ss =rs.getString("id") + "\t" + rs.getString("name") + "\t" + rs.getString("english") + "\t" + rs.getString("math") + "\t" + rs.getString("chinese");
            return ss;
        }
        else return null;
        
       
    }
    

    public static int compl(String a, String b) throws Exception {
        Class.forName(DRIVER_CLASS);//load driver
        //On the base of URL user password connect SQL
        Connection conn = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
        Statement stmt = conn.createStatement();// createһ��Statement�
        // stmt.executeUpdate("select id from stu_manage where name="+a);
        String sql ="select * from stu where name='" + a + "'";
        System.out.println("sql+++++++++++:"+sql);
        ResultSet rs = stmt.executeQuery(sql);   
        
        if (rs.next()) {
            String str = rs.getString("password");
            if (str.equals(b)) {

                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
        

    }

  

    static void p(String a) {
        System.out.println(a);
    }
}
//display 
    //id VARCHAR(36) PRIMARY KEY,name VARCHAR(100),sex VARCHAR(4),student_id VARCHAR(50),Escore VARCHAR(50),Mscore VARCHAR(50),Cscore
//    private static void show(Statement stmt) throws SQLException{
//     ResultSet rs = stmt.executeQuery("SELECT * FROM stu_info");
//        while (rs.next()) {
//          p(rs.getString(1) + "\t" + rs.getString("name") + "\t" + rs.getString("sex")+"\t"+rs.getString(4));
//        }
//    }
//    String str ="";
//    public int compl(String a,String b){
//         if(str.equals(a)){
//             return 1;
//         }
//         else 
//         return 0;
//    }
////   

